<template>
  <div class="Layout">
    <div class="Subtitle">技巧</div>
    <div class="Minortitle">固化无初值的目标属性</div>
    <div>应用的transition的属性必须拥有精确初值，即非initial、auto、default等，否则渐变动画不会生效。</div>
    <div class="Gap-S"></div>
    <div>对于一些没有初值的场景，比如高度有内容决定但希望高度可以折叠，可以在渲染完毕后使用JS固化属性值。</div>
    <div>示例：</div>
    <div id="example">
      <div class="block">
        <div>#1-无初始高度</div>
        <div id="div-1" class="div">
          这一路上走走停停
          顺着少年漂流的痕迹
          迈出车站的前一刻
          竟有些犹豫
        </div>
      </div>
      <div class="block">
        <div>#2-有初始高度</div>
        <div id="div-2" class="div initiated">
          我终将青春还给了她
          连同指尖弹出的盛夏
          心之所动 就随风去了
          以爱之名 你还愿意吗
        </div>
      </div>
      <div class="block">
        <div>#3-固化初始高度</div>
        <div id="div-3" class="div">
          再次看到你
          微凉晨光里
          笑得很甜蜜
        </div>
      </div>
    </div>
    <div class="Divide-3 Padding-S">
      <div class="Code">{
        height: auto;
        }
      </div>
    </div>
    <div class="Divide-3 Padding-S">
      <div class="Code">{
        height: 140px;
        }
      </div>
    </div>
    <div class="Divide-3 Padding-S">
      <div class="Code">{
        height: auto;
        }

        let div3 = document.getElementById('div-3')<br />div3.style.height = div3.offsetHeight</div>
    </div>
  </div>
</template>

<style>
  #example {
    display: flex;
    justify-content: space-around;
    height: 200px;
    margin-top: 30px;
  }

  .block {
    width: 200px;
  }

  .div {
    overflow: hidden;
    margin-bottom: 2rem;
    border: 1px solid lightgray;
    transition: height 0.5s;
    white-space: pre-wrap;
  }

  .div.folded {
    height: 0 !important;
  }

  .div.initiated {
    height: 140px;
  }

  .button {
    float: right;
    cursor: pointer;
  }
</style>

<script>
  let div3 = document.getElementById('div-3')
  div3.style.height = div3.offsetHeight + 'px'

  let param = {
    toggle_1: () => {
      document.getElementById('div-1').classList.toggle('folded')
    },
    toggle_2: () => {
      document.getElementById('div-2').classList.toggle('folded')
    },
    toggle_3: () => {
      document.getElementById('div-3').classList.toggle('folded')
    }
  }
  const gui = new GUI();
  for (let key in param) {
    gui.add(param, key)
  }
  Broadcast.once('render', () => {
    gui.destroy()
  })
</script>